#pragma once

#include <iostream>
#include <string>

std::string opers="+-*/%";

enum
{
    DivZero=1,
    ModZero,
    Unknown
};

//任务
class Task
{
public:
    //构造
    Task(int x, int y, char op) 
    : _data1(x)
    , _data2(y)
    , _oper(op)
    , _result(0)
    , _exitcode(0)
    {}

    void run()
    {
        switch (_oper)
        {
        case '+':
            _result = _data1 + _data2;
            break;
        case '-':
            _result = _data1 - _data2;
            break;
        case '*':
            _result = _data1 * _data2;
            break;
        case '/':
            {
                if(_data2 == 0) _exitcode = DivZero;
                else _result = _data1 / _data2;
            }
            break;
        case '%':
            {
                if(_data2 == 0) _exitcode = ModZero;
                else _result = _data1 % _data2;
            }            
            break;
        default:
            _exitcode = Unknown;
            break;
        }
    }

    //括号重载
    void operator()()
    {
        run();
    }

    //打造结果字符串
    std::string GetResult()
    {   
        //1+2=3 [code:0]
        std::string r = std::to_string(_data1);
        r += _oper;
        r += std::to_string(_data2);
        r += "=";
        r += std::to_string(_result);
        r += " [code:";
        r += std::to_string(_exitcode);
        r += "]";

        return r;
    }

    //打造任务字符串
    std::string GetTask()
    {
        //1+2=?
        std::string r = std::to_string(_data1);
        r += _oper;
        r += std::to_string(_data2);
        r += "=?";

        return r;
    }

    //析构
    ~Task()
    {}

private:
    int _data1;
    int _data2;
    char _oper; //操作符

    int _result; //结果
    int _exitcode; //正确码
};